package com.itelite.common.util;

import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
import cn.afterturn.easypoi.excel.export.ExcelExportService;
import org.apache.poi.ss.usermodel.Sheet;

import java.util.List;

/**
 * @author 沈洋 邮箱:1845973183@qq.com
 * @create 2021/8/9-21:42
 **/
public class MyExcelExportService extends ExcelExportService {
    @Override
    public void setCellWith(List<ExcelExportEntity> excelParams, Sheet sheet) {
        for (int i = 0; i < excelParams.size(); i++) {
            if (excelParams.get(i).getList() != null) {
                List<ExcelExportEntity> list = excelParams.get(i).getList();
                for (int j = 0; j < list.size(); j++) {
                    // 调整每一列宽度
                    sheet.autoSizeColumn((short) i);
                    // 解决自动设置列宽中文失效的问题
                    sheet.setColumnWidth(i, sheet.getColumnWidth(j) * 10);
                }
            } else {
                // 调整每一列宽度
                sheet.autoSizeColumn((short) i);
                // 解决自动设置列宽中文失效的问题
                sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 10);
            }
        }
    }
}
